package com.service.cook.imp;

import java.text.SimpleDateFormat;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dao.cook.CtomorrowmenuDaoY;
import com.po.Dish;
import com.po.TomorrowmenuY;
import com.service.cook.CtomorrowmenuServiceY;

@Service
public class CtomorrowmenuServiceImpY implements CtomorrowmenuServiceY {
	@Resource(name = "ctomorrowmenuDaoImpY")
	private CtomorrowmenuDaoY ctomorrowmenuDaoY;

	@Override
	public List<TomorrowmenuY> getTomorrowmenuList() {
		List<TomorrowmenuY> list = ctomorrowmenuDaoY.getTomorrowmenuList();
		return list;
	}

	@Override
	public int delTomorrowmenu() {
		int i = ctomorrowmenuDaoY.delTomorrowmenu();
		return i;
	}

	@Override
	public int addTomorrowmenus(List<Dish> menus) {
		
		ctomorrowmenuDaoY.delTomorrowmenu();
		int i = ctomorrowmenuDaoY.addTomorrowmenus(menus);
		return i;
	}

	@Override
	public int haveTomorrow() {
		List<TomorrowmenuY> list = ctomorrowmenuDaoY.getTomorrowmenuList();
		java.sql.Date udata = new java.sql.Date(System.currentTimeMillis());
		if (list.size() != 0) {
			TomorrowmenuY tomorrowmenu = list.get(0);
			java.sql.Date sdata=new java.sql.Date(tomorrowmenu.getMenu_time().getTime());
			SimpleDateFormat f=new SimpleDateFormat("yyyy-MM-dd");
			String s=f.format(sdata);
			String u=f.format(udata);
			if (s.equals(u))
				return 1;
			else return 0;
		} else
			return 0;
	}

	@Override
	public TomorrowmenuY getTomorrowmenu(String id) {
		TomorrowmenuY tomorrowmenu=ctomorrowmenuDaoY.getTomorrowmenu(id);
		return tomorrowmenu;
	}

}
